<?php
$news = $viewModel->get('listNews');
$cates = $viewModel->get("categories");
$totalPage = $viewModel->get("totalPage");
$countPage = ceil($totalPage->totalRecord / 15);

foreach ($cates AS $cate) {
    if ($cate->category_id == $news[0]->category_id) {
        $curCate = $cate->category_name;
    }
}
?>
<div id="leftcol">
    <div class="leftads">
        <a><a href="<?php echo BASE_URL . 'home' ?>">TRANG CHỦ</a><?php echo htmlentities(" > ") ?><?php echo $curCate; ?></a> 
        <hr>
    </div>
    <div class="listnews-hotnews">
        <div class="listnews-content">
            <?php
            if (empty($news)) {
                echo 'Không có dữ liệu';
            } else {
                foreach ($news as $new) {
                    $imgAlt = Helper::getFirstImage($new->body);
                    ?>
                    <div class="listnews-item">
                        <a href="<?php echo BASE_URL ?>Home/viewDetail/<?php echo $new->news_id ?>" ><img src="<?php echo $imgAlt[0]; ?>" alt="<?php echo $imgAlt[1]; ?>" width="137px" height="90px" /></a><br>
                        <a href="<?php echo BASE_URL ?>Home/viewDetail/<?php echo $new->news_id ?>"><?php echo $new->title ?></a>
                        <p><?php echo $new->content ?></p>
                    </div><div style="border: .5px solid gray; width: 70%; margin: 0px auto;"></div>
                    <?php
                }
            }
            ?>
        </div>
    </div>
    <div style="padding: 10px; border: 1px #cccccc solid; background: #ffffff; border-radius: 5px; ">
        <?php
        if (empty($_GET['page'])) {
            $_GET['page'] = 1;
        }
        ?>
        <ul class="tsc_pagination tsc_paginationC tsc_paginationC06">
            <?php if ($_GET['page'] > 1) {
                ?>
                <li><a href="<?php echo BASE_URL . "Home/ViewsContent/" . $_GET['id'] . "/1"; ?>" class="first">Đầu</a></li>
                <li><a href="<?php echo BASE_URL . "Home/ViewsContent/" . $_GET['id'] . "/" . ($_GET['page'] - 1); ?>" class="previous">Trước</a></li>
                <?php
            }
            for ($i = 1; $i <= $countPage; $i++) {
                ?>
                <li>
                    <a class="<?php echo ($_GET['page'] == $i) ? 'current' : ""; ?>" href="<?php echo BASE_URL . "Home/ViewsContent/" . $_GET['id'] . "/" . $i; ?>"><?php echo $i; ?></a>
                </li>
                <?php
            }
            if ($countPage > $_GET['page']) {
                ?>

                <li><a href="<?php echo BASE_URL . "Home/ViewsContent/" . $_GET['id'] . "/" . ($_GET['page'] + 1); ?>" class="next">Sau</a></li>
                <li><a href="<?php echo BASE_URL . "Home/ViewsContent/" . $_GET['id'] . "/" . $countPage; ?>" class="last">Cuối</a></li>
                <?php } ?>
        </ul>
    </div>
</div>